package com.studentstreet.tools;

import java.util.Comparator;

import com.studentstreet.entities.GoodsEntity;
import com.studentstreet.entities.SellerEntity;

public class SortById implements Comparator {

	@Override
	public int compare(Object one, Object another) {
		// 当排序的是商品时
		if (one instanceof GoodsEntity) {
			GoodsEntity goods1 = (GoodsEntity) one;
			GoodsEntity goods2 = (GoodsEntity) another;
			if (goods1.getId() > goods2.getId())
				return 1;
			else if (goods1.getId() < goods2.getId()) {
				return -1;
			}
			// 当要排序的是商家时
		} else if (one instanceof SellerEntity) {
			SellerEntity seller1 = (SellerEntity) one;
			SellerEntity seller2 = (SellerEntity) another;
			if (seller1.getId() > seller2.getId())
				return 1;
			else if (seller1.getId() < seller2.getId()) {
				return -1;
			}
		}
		return 0;
	}

}
